﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CalculatorGUI
{
    public partial class EqxControl : UserControl
    {
        List<CalcTextBox> txtList = new List<CalcTextBox>();
        List<CheckBox> chkList = new List<CheckBox>();

        Brush Eq1Color = new SolidColorBrush(Color.FromArgb(255, 255, 140, 0));
        Brush Eq2Color = new SolidColorBrush(Color.FromArgb(255, 70, 130, 180));
        Brush Eq3Color = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
        Brush Eq4Color = new SolidColorBrush(Color.FromArgb(255, 50, 205, 50));

        /// <summary>
        /// Constructor
        /// </summary>
        public EqxControl()
        {
            InitializeComponent();
            calcTextBox1.Foreground = Eq1Color;
            calcTextBox2.Foreground = Eq2Color;
            calcTextBox3.Foreground = Eq3Color;
            calcTextBox4.Foreground = Eq4Color;
            radioButton1.Foreground = Eq1Color;
            radioButton2.Foreground = Eq2Color;
            radioButton3.Foreground = Eq3Color;
            radioButton4.Foreground = Eq4Color;

            txtList.Add(calcTextBox1);
            txtList.Add(calcTextBox2);
            txtList.Add(calcTextBox3);
            txtList.Add(calcTextBox4);
            chkList.Add(radioButton1);
            chkList.Add(radioButton2);
            chkList.Add(radioButton3);
            chkList.Add(radioButton4);
        }

        /// <summary>
        /// This method will change the focus of the custom text boxes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void calcTextBox1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            for (int i = 0; i < txtList.Count; i++)
            {
                txtList[i].Selected = false;
            }
            ((CalcTextBox)sender).Selected = true;
        }

        /// <summary>
        /// Handles most of the text input from the buttons, just passes in the buttons tags
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            foreach (CalcTextBox t in txtList)
            {
                if (t.Selected)
                {
                    t.Text = t.Text + ((Button)sender).Tag;
                }
            }
        }

        /// <summary>
        /// Handler for the erase button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button31_Click(object sender, RoutedEventArgs e)
        {
            foreach (CalcTextBox t in txtList)
            {
                if (t.Selected)
                {
                    if (t.Text.Length > 0)
                    {
                        t.Text = t.Text.Remove(t.Text.Length - 1);
                    }
                }
            }
        }

        /// <summary>
        /// Handler for the clear button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button32_Click(object sender, RoutedEventArgs e)
        {
            foreach (CalcTextBox t in txtList)
            {
                if (t.Selected)
                {
                    t.Text = string.Empty;
                }
            }
        }

        /// <summary>
        /// Getter and setter for the text box list
        /// </summary>
        public List<CalcTextBox> TxtList
        {
            get { return txtList; }
            set { txtList = value; }
        }

        /// <summary>
        /// Getter and setter for the Check box list
        /// </summary>
        public List<CheckBox> ChkList
        {
            get { return chkList; }
            set { chkList = value; }
        }
    }
}
